#need to be ProxyingController's Class methods

module ProxyingUrlHandlerHelper
    def remove_location_replace(url, doc)
        doc.search("//script") do |script|
            if script.inner_html.index /location\.replace/
                script.inner_html = ""
            elsif script.inner_html.index /location\.href.*=/
                puts "removing #{script}"
                script.inner_html = ""
            end
        end
    end

    def remove_meta_refresh(url, doc)
        doc.search("meta[@http-equiv=refresh]").remove
    end

    def append_base(url, doc)
        doc = @page.search("")
        head = doc.search("head")
        head.search("/").last.after("<base href=#{baseURL(@url)}/ >")
        doc.search("body").search("/").first.after("<a href=index.php>index.php</a>")
    end

    def nothing(url, doc)
        puts "nothing... #{url}"
    end
end